﻿@model PollModel
@using SmartStore.Web.Models.Polls;
@{
    Html.AddScriptParts("~/Scripts/public.voting.js");
}

<div id="poll-block-@(Model.Id)" class="card poll-item mt-3">
    <div class="card-header">@Model.Name</div>
    @if (Model.AlreadyVoted)
    {
        <div class="poll-results card-body">
            @foreach (var item in Model.Answers)
            {
                <div class="answer">
                    <div class="vote-result-percent float-right">@((item.PercentOfTotalVotes/100).ToString("#0.##%"))</div>
                    <div class="vote-result-line">@item.Name (@item.NumberOfVotes)</div>

                    <div class="progress">
                        <div class="progress-bar bg-info" role="progressbar" 
                             style="width: @(Math.Round(item.PercentOfTotalVotes, 0))%" 
                             aria-valuenow="@(Math.Round(item.PercentOfTotalVotes, 0))" aria-valuemin="0" aria-valuemax="100"></div>
                    </div>

                </div>
            }
            <div class="poll-total-votes text-success">@string.Format(T("Polls.TotalVotes").Text, Model.TotalVotes)</div>
        </div>
    }
    else
    {
        <div class="poll-take-poll card-body">
            
            @foreach (var item in Model.Answers)
            {
                <div class="radio">
                    <label><input type="radio" id="pollanswers-@(item.Id)" name="pollanswers-@(Model.Id)" value="@item.Id" />@item.Name</label>
                </div>
            }
            
            <button id="vote-poll-@(Model.Id)" 
                data-id="@(Model.Id)" 
                data-target="@(Url.Action("Vote"))" 
                data-message="@T("Polls.SelectAnswer")" 
                class="btn btn-warning btn-block btn-votenow">
                @T("Polls.Vote")
            </button>

        </div>
    }
</div>
